package com.xdtech.sys.util;

import java.util.Date;
import java.util.Properties;

import javax.mail.internet.MimeMessage;

import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;

public class MailUtil {
    public static void send(String userMail,String username,String password) throws Exception {
        JavaMailSenderImpl javaMail = new JavaMailSenderImpl();
        //默认商城发送用的用户和密码
        javaMail.setUsername("zzxstudynumber");
        javaMail.setPassword("zzx123456");
        Properties prop = new Properties();
        prop.setProperty("mail.smtp.host", "smtp.163.com");
        prop.setProperty("mail.smtp.auth", "true");
        javaMail.setJavaMailProperties(prop);
        MimeMessage message = javaMail.createMimeMessage();
        MimeMessageHelper messageHelper = new MimeMessageHelper(message,true,"UTF-8");
        messageHelper.setSubject("JMax密码找回");
        messageHelper.setSentDate(new Date());
        messageHelper.setFrom("zzxstudynumber@163.com","JMax平台");
        messageHelper.setTo(userMail);
        StringBuffer sb = new StringBuffer();
        sb.append("<html><head><META http-equiv=Content-Type content='text/html; charset=UTF-8'></HEAD><title>农耕食代</title></head><body>")
          .append("<p>亲爱的"+username+"：</p>")
          .append("&nbsp;&nbsp;&nbsp;&nbsp;你的登录密码："+password+"<br/>") 
          .append("&nbsp;&nbsp;&nbsp;&nbsp;请妥善保管好您的密码。")
          .append("</body></html>");
        messageHelper.setText(sb.toString(), true);
        javaMail.send(message);
    }
    
    public static void main(String[] args) throws Exception {
    	MailUtil.send("358744287@qq.com", "max", "123456");
	}
}
